<?php
// 商品分页
require $this->website['path']['action'] . '/admin/islogin.php';

$json = array('status' => 'ok', 'msg' => 'ok', 'data' => '');
$sys = fn_configura($this->website, 'sys');

$tid = fn_post('tid');
$k = fn_post('k');
$p = fn_post('p', 1);

$num = 20;

$this->website['class']['db']
	->table('product')
// ->field('')
	->order('id desc')
	->page($p)
	->num($num);
if ($tid && $k) {
	$this->website['class']['db']
		->where('tid=? and tit like ?', $tid, '%' . $k . '%');
} elseif ($tid) {
	$this->website['class']['db']
		->where('tid=?', $tid);
} elseif ($k) {
	$this->website['class']['db']
		->where('tit like ?', '%' . $k . '%');
}
$data = $this->website['class']['db']->paging();

foreach ($data['data'] as &$v) {
	$type = $this->website['class']['db']
		->table('type')
		->field('tit')
		->where('id=?', $v['tid'])
		->one();
	$shops = $this->website['class']['db']
		->table('shops')
		->field('tit')
		->where('id=?', $v['sid'])
		->one();
	$v['type'] = $type['tit'] ?? '';
	$v['shops'] = ($shops['tit'] ?? '无店铺');
}
// $json['sql'] = $this->website['class']['db']->sql;
$json['data'] = $data;

$this->json_encode($json);